package com.zzyl.config;

import com.zzyl.intercept.ManagerLoginInterceptor;
import com.zzyl.intercept.MobileInterceptor;
import com.zzyl.properties.SecurityProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 *  WebMvc高级配置类
 */
@Configuration
public class WebMvcConfig implements WebMvcConfigurer {
    @Autowired
    private MobileInterceptor mobileInterceptor;
    @Autowired
    private ManagerLoginInterceptor managerLoginInterceptor;
    @Autowired
    private SecurityProperties securityProperties;

    //拦截的时候过滤掉swagger相关路径和登录相关接口
    private static final String[] EXCLUDE_PATH_PATTERNS = new String[]{"/swagger-ui.html", "/webjars/**", "/swagger-resources", "/v2/api-docs", "/customer/user/login"};

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // 小程序登录拦截器
        registry.addInterceptor(mobileInterceptor).addPathPatterns("/customer/**").excludePathPatterns(EXCLUDE_PATH_PATTERNS);
        // 管理端登录权限拦截器
        registry.addInterceptor(managerLoginInterceptor).addPathPatterns("/**").excludePathPatterns(securityProperties.getIgnoreUrl());
    }

}
